package kr.hkit.androidcomplete02.ch16;

import java.util.Calendar;

import kr.hkit.androidcomplete02.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

public class ShowDialogEx extends Activity {
	final static int SAMPLE_DLG = 0;
	final static int QUESTION_DLG = 1;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		Log.d("ShowDialogEx", "onCreate");
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch16_showdialog);
	}

	@SuppressWarnings("deprecation")
	public void mOnClick(View v) {
		switch (v.getId()) {
		case R.id.call:
			showDialog(SAMPLE_DLG);
			break;
		case R.id.call2:
			showDialog(QUESTION_DLG);
			break;
		}
	}

	@Override
	protected Dialog onCreateDialog(int id) {
		Log.d("ShowDialogEx", "onCreateDialog"
				+ (id == 0 ? "SAMPLE_DLG" : "QUESTION_DLG"));
		switch (id) {
		case SAMPLE_DLG:
			return new AlertDialog.Builder(this).setTitle("notice")
					.setMessage("opened Dialog")
					.setIcon(R.drawable.ic_launcher)
					.setPositiveButton("Close Dialog", null).create();
		case QUESTION_DLG:
			return new AlertDialog.Builder(this).setTitle("Question")
					.setMessage("Do you have a breakfirst?")
					.setPositiveButton("Eating", null)
					.setNegativeButton("Not Eating", null).create();
		}
		return null;
	}

	@Override
	protected void onPrepareDialog(int id, Dialog dialog) {
		Log.d("ShowDialogEx", "onPrepareDialog"
				+ (id == 0 ? "SAMPLE_DLG" : "QUESTION_DLG"));
		switch (id) {
		case SAMPLE_DLG://onCreateDialog equals
			break;
		case QUESTION_DLG:
			Calendar cal = Calendar.getInstance();
			String stime = String.format("%d : %d :%d", cal.get(Calendar.HOUR_OF_DAY),
					cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND)
					);
			dialog.setTitle(stime);
			break;
		}
	}

}
